package com.example.yuapiinterface.controller;

import com.example.weisdk.entity.User;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/name")
public class NameController {
    @GetMapping("/")
    public String getNameByGet(String name){
        return "GET 你的名字是" +name;
    }
    @PostMapping("/POST")
    public String getNameByPost(String name){
        return "POST 你的名字是" +name;
    }
    @PostMapping("/JSON")
    public String getUserNameByPost(@RequestBody User user, HttpServletRequest request){
        String accessKey=request.getHeader("accessKey");
        String nonce=request.getHeader("nonce");
        String timestamp=request.getHeader("timestamp");
        String sign=request.getHeader("sign");
        String body=request.getHeader("body");

        //TODO 校验accessKey

        //TODO 时间和当前时间不能超过15分钟
        if (Long.parseLong(nonce)>10000){
            throw new RuntimeException("无权限");
        }
        return "Post 用戶的名字是" +user.getUserName();
    }
}
